home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / vbcc / machines / amiga68k / libsrc / amigalib / createtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  1.6 KB  |  66 lines

  1. /*
  2. ** compiles with inline only in large data! AddTask() uses too many
  3. ** nonscratch registers :( use of assembler version is recommended
  4. */
  5. #include <exec/tasks.h>
  6. #include <exec/memory.h>
  7. #include <exec/execbase.h>
  8. #include <clib/alib_protos.h>
  9. #include <proto/exec.h>
  10. #include <clib/exec_protos.h>
  11.  
  12. struct newMemList
  13. {
  14.   struct Node nml_Node;
  15.   UWORD nme_NumEntries;
  16.   struct MemEntry nml_ME[2];
  17. };
  18.  
  19. const struct newMemList MemTemplate =
  20. { {0,},
  21.   2,
  22.   { {MEMF_CLEAR|MEMF_PUBLIC, sizeof(struct Task)},
  23.     {MEMF_CLEAR, 0} }
  24. };
  25.  
  26. struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize)
  27. {
  28.   struct Task *newtask,*task2;
  29.   struct newMemList nml;
  30.   struct MemList *ml;
  31.  
  32.   stacksize=(stacksize+3)&~3;
  33.   {
  34.     long *p1,*p2;
  35.     int i;
  36.  
  37.     for (p1=(long *)&nml,p2=(long*)&MemTemplate,i=7; i; *p1++=*p2++,i--) ;
  38.     *p1=stacksize;
  39.   }
  40. /*  if (!(((unsigned int)ml=AllocEntry((struct MemList *)&nml)) & (1<<31)))*/
  41. /*  was dieser gcc alles als lvalue durchgehen laesst...    */
  42.   ml=AllocEntry((struct MemList *)&nml);
  43.   if(!((unsigned int)ml&(1<<31)))
  44.   {
  45.     newtask=ml->ml_ME[0].me_Addr;
  46.     newtask->tc_Node.ln_Type=NT_TASK;
  47.     newtask->tc_Node.ln_Pri=pri;
  48.     newtask->tc_Node.ln_Name=name;
  49.     newtask->tc_SPReg=(APTR)((ULONG)ml->ml_ME[1].me_Addr+stacksize);
  50.     newtask->tc_SPLower=ml->ml_ME[1].me_Addr;
  51.     newtask->tc_SPUpper=newtask->tc_SPReg;
  52.     NewList(&newtask->tc_MemEntry);
  53.     AddHead(&newtask->tc_MemEntry,(struct Node *)ml);
  54.     task2=(struct Task *)AddTask(newtask,initpc,0);
  55.     if (SysBase->LibNode.lib_Version>36 && !task2)
  56.     {
  57.       FreeEntry(ml); newtask=NULL;
  58.     }
  59.   }
  60.   else
  61.     newtask=NULL;
  62.  
  63.   return newtask;
  64. }
  65.  
  66.